layui.use(['layer','jquery','form','table','laydate'],function () {
    let form = layui.form;
    let layer = layui.layer;
    let $ = layui.$;
    let table = layui.table;
    let laydate = layui.laydate;
    //刷新功能
    $('#refresh').click(function () {
        location.reload();
    });
    //返回功能
    $('#goBack').click(function () {
        parent.tabParentChange(3);
    })
    //操作时间渲染
    laydate.render({
        elem: '#createDate',
        type: 'datetime'
    });
    //查看全部课程日志
    getCourseLogs();
    form.on('submit(search)',function (obj) {
        getCourseLogs(obj.field);
        return false;
    });
    function getCourseLogs(log) {
        $.ajax({
            url: '/log/getCourseLogs',
            data: log,
            dataType: 'json',
            success: function (data) {
                courseLogsTableRender(data.data);
            }
        });
    }
    function courseLogsTableRender(logs) {
        table.render({
            elem: '#logsTable',
            title: '日志列表',
            data: logs,
            limit: 10,
            toolbar: '#course_thead',
            page:{
                layout:['count','prev','page','next','limit','skip','refresh'],
                //limits:[3,6,9],
                first:"首页",
                last:"尾页",
            },
            cols: [[
                {type:'checkbox'},
                {title:'序号',align:'center',templet:function(data){
                        return data.LAY_INDEX;
                    }},
                {field:"account",title:"执行人",align:'center'},
                {field:"createDate",title:"执行时间",align:'center'},
                {field:"",title:"操作类型",align:'center',templet:function(data){
                        if(data.type == 2){
                            return '增加';
                        }else if(data.type == 3){
                            return '删除';
                        }else if(data.type == 4){
                            return '修改';
                        }else if(data.type == 5){
                            return '查看';
                        }
                    }},
                {field:"remark",title:"备注",align:'center'},
                {field:'',title:"操作",align:'center',toolbar: '#operation'}
            ]]
        })
    }
    table.on('tool(logsTable)',function (obj) {
        if(obj.event == 'deleteLogTable'){
            var layerIndex = layer.confirm('确定要删除日志么?', {
                btn: ['确定','取消'],
                title: '删除日志',
            }, function(){
                deleteLog(obj.data.logId);
                layer.close(layerIndex);
            });
        }
    })
    function deleteLog(logId) {
        $.ajax({
            url: '/log/deleteLog',
            type: 'post',
            data: {logId : logId},
            dataType: 'json',
            success:function (data) {
                if(data.data){
                    layer.msg('删除成功');
                    getCourseLogs();
                }
            }
        });
    }
})